import '../public/index'
import url from '../data/url'
import request from '../data/request'
import { header } from '../data/config'
import { getUrlParam } from '../data/util'

const { base }              = url
const { getFeedBackDetail } = request

let data = new Vue({
  el: '#data',
  data: () => ({
    content: '',
    createTime: '',
    name: '',
    iconList: ''
  }),
  mounted: function () {
    this.initData()
  },
  methods: {
    initData: function () {
      let id      = getUrlParam('id'),
          loading = layer.msg('加载数据中...', {
            icon: 16,
            time: 0
          })

      $.ajax({
        headers: header,
        url: base + getFeedBackDetail,
        data: {
          id: id
        }
      })
        .done(function (res) {
          if (res.code !== 0) {
            layer.msg(error || '加载失败！', {
              icon: 5
            })
            return
          }

          $.extend(data.$data, res.object)

          const iconList = res.iconList.map(v => (
            {
              type: v.type,
              dataId: v.dataId,
              url: base + v.ulr
            }
          ))

          data.iconList = iconList
        })
        .fail(function () {
          layer.msg(error || '加载失败！', {
            icon: 5
          })
        })
        .always(function () {
          layer.close(loading)
        })
    }
  }
})

